Velsn.Tools = {
		getTarget : function(event){
			return event.srcElement ? event.srcElement : event.target;
		},
		
		absPos :function(node){
            var x=y=0;
            do{
                x+=node.offsetLeft;
                y+=node.offsetTop;
            }while(node=node.offsetParent);   
            return{   
                'x':x,   
                'y':y   
            };         
        }
};
Velsn.MenuManager = {
	
	_menus : {},
	
	createMenu : function(datas,type,input){
		var id = $(input).attr("id");
		this._menus[id] = eval("new Velsn." + type + "(datas,input)");
		return this._menus[id];
	},
	
	show : function(event,datas,type,isNew) {
		var me = this;
		var id = $(Velsn.Tools.getTarget(event)).attr("id");
		if (!me._menus[id]) 
			me._menus[id] = eval("new Velsn." + type + "(datas)");
		if (me._currentMenu && me._currentMenu != me._menus[id]) 
			me._currentMenu.hide();
		if (isNew) 
			me._menus[id].setDatas(datas);
		me._menus[id].show(event);
		me._currentMenu = me._menus[id];
	},
	resetAll : function() {
		var me = this;
		for ( var key in me._menus) {
			me._menus[key].reset();
		}
	},
	
	getMenu : function(id) {
		return this._menus[id];
	}
	
};
function setDefaultEnd(endEl){
	var scopeInputs = $('input', endEl.parentElement);
	if(scopeInputs[0].value){
		scopeInputs[1].value = Math.round(scopeInputs[0].value * 1.2);
	}
	endEl.select();
}
Velsn.ScopeInputMenu = Velsn.Class(Velsn.BaseMenu,{
	
	construct : function(datas,input){
		var me = this;
		me._input = input;
		me._closeCB = datas.closeCB;
		me._config = datas.config;
		me._div = $('<div style="position:absolute;display:none;z-index:1000;width:150px;height:45px;" class="popmenu">'
				+'<div><input type="text" maxLength="5" style="width:55px;" onKeypress="if (event.keyCode<48||event.keyCode>57)event.returnValue=false;" onkeydown="if(event.keyCode==13)event.keyCode=9"/> 到 <input type="text" maxLength="5" style="width:55px;" onFocus="setDefaultEnd(this);" onKeypress="if (event.keyCode<48||event.keyCode>57)event.returnValue=false;" onkeydown="if(event.keyCode==13)event.keyCode=9"/></div>'
				+'<div class="btnBar"><input class="velsnbtn" type="button" value="确定"/><input class="velsnbtn" type="button" value="清空" style="margin-left:5px;"/></div>'
				+'</div>');
		me._isAutoWidth = false;
		me._div.appendTo($("body"));
		me._div.find("input[value='确定']").click(function(event){
			me._ok(event);
		});
		me._div.find("input:last").click(function(){
			me._clear();
		});
		me._cueDiv = $('<div style="position:absolute;padding:4px 0px 4px 4px;z-index:1001;width:105px;font-weight:bold;font-size:14px;background-color: #ECE9D8;color:red;border:1px solid red;">输入范围错误！</div>');
		me._cueDiv.click(function(event){
			me._stopBubble(event);
		});
		if (datas) 
			me.setUiId(datas.startInputId, datas.endInputId);
	},
	
	_showCue : function(event) {
		var me = this;
		me._cueDiv.css("left",event.pageX+"px");
		me._cueDiv.css("top",(event.pageY-20)+"px");
		me._cueDiv.appendTo($("body"));
		me._cueDiv.fadeIn("fast");
		if (me._interval) 
			clearInterval(me._interval);
		me._interval = setInterval(function(){
				me._cueDiv.fadeOut("fast");
		}, 1000);
	},
	
	show : function(event) {
		var me = this;
		//me.config = config;
		Velsn.BaseMenu.prototype.show.apply(me,arguments);
		me._div.find("input:first").focus();
	},
	
	hide : function() {
		var me = this;
		if(me._isShow)
			me._ok(null,true);
		Velsn.BaseMenu.prototype.hide.apply(me,arguments);
	},
	
	_stopBubble : function(event) {
		Velsn.BaseMenu.prototype._stopBubble.apply(this,arguments);
	},
	
	_ok : function(event,isHide) {
		var me = this;
		var inputs = me._div.find("input");
		var startValue = inputs[0].value;
		var endValue = inputs[1].value;
		if (startValue && endValue && parseInt(startValue) > parseInt(endValue)) {
			if (event) 
				me._showCue(event);
			return;
		}else if (startValue || endValue) 
			me._input.value = this._getConfig('prefix') +
			(startValue ? startValue : 0) + " 到 " + (endValue ? endValue : "不限") +
			this._getConfig('suffix');
		if (!isHide) 
			me.hide();
	},
	
	_getConfig: function(itemName){
		var me = this;
		return (me._config && me._config[itemName])?me._config[itemName]:"";
	},
	
	setUiId : function(startInputId,endInputId) {
		var me = this;
		var inputs = me._div.find("input");
		inputs[0].id = startInputId;
		inputs[0].name = startInputId;
		inputs[1].id = endInputId;
		inputs[1].name = endInputId;
	},
	
	getValue : function() {
		var me = this;
		var inputs = me._div.find("input");
		return [inputs[0].value,(inputs[1].value == "不限" ? "" : inputs[1].value)];
	},
	
	setValue : function(value) {
		var me = this;
		var inputs = me._div.find("input");
		if (isNaN(value[0])) 
			inputs[0].value = "";
		else
			inputs[0].value = value[0];
		if (isNaN(value[1])) 
			inputs[1].value = "";
		else
			inputs[1].value = value[1];
		me._ok();
	},
	
	reset : function() {
		this._clear();
	},
	
	_clear : function() {
		var me = this;
		var inputs = me._div.find("input");
		inputs[0].value = "";
		inputs[1].value = "";
		if (me._config.title) 
			me._input.value = me._config.title;
		else
			me._input.value = "";
	}
	
});

Velsn.ScopeDateMenu = Velsn.Class(Velsn.BaseMenu,{ 
	construct : function(datas,input){
		var me = this;
		me._input = input;
		me._closeCB = datas.closeCB;
		me._config = datas.config;
		me._div = $('<div style="position:absolute;display:none;z-index:3000;width:150px;height:45px;" class="popmenu">'
				+'<div><input type="text" maxLength="5" style="width:55px;" onclick="WdatePicker({isShowOthers:false,dateFmt:"yyyy-MM-dd"})"  /> 到 <input type="text" maxLength="5" style="width:55px;"  onclick="WdatePicker({isShowOthers:false,dateFmt:"yyyy-MM-dd"})" /></div>'
				+'<div class="btnBar"><input class="velsnbtn" type="button" value="确定"/><input class="velsnbtn" type="button" value="清空" style="margin-left:5px;"/></div>'
				+'</div>');
		me._isAutoWidth = false;
		me._div.appendTo($("body"));
		me._div.find("input[value='确定']").click(function(event){
			me._ok(event);
		});
		me._div.find("input:last").click(function(){
			me._clear();
		});
		me._cueDiv = $('<div style="position:absolute;padding:4px 0px 4px 4px;z-index:3001;width:105px;font-weight:bold;font-size:14px;background-color: #ECE9D8;color:red;border:1px solid red;">输入范围错误！</div>');
		me._cueDiv.click(function(event){
			me._stopBubble(event);
		});
		if (datas) 
			me.setUiId(datas.startInputId, datas.endInputId);
	},
	
	_showCue : function(event) {
		var me = this;
		me._cueDiv.css("left",event.pageX+"px");
		me._cueDiv.css("top",(event.pageY-20)+"px");
		me._cueDiv.appendTo($("body"));
		me._cueDiv.fadeIn("fast");
		if (me._interval) 
			clearInterval(me._interval);
		me._interval = setInterval(function(){
				me._cueDiv.fadeOut("fast");
		}, 1000);
	},
	
	show : function(event) {
		var me = this;
		//me.config = config;
		Velsn.BaseMenu.prototype.show.apply(me,arguments);
		me._div.find("input:first").focus();
	},
	
	hide : function() {
		var me = this;
		if(me._isShow)
			me._ok(null,true);
		Velsn.BaseMenu.prototype.hide.apply(me,arguments);
	},
	
	_stopBubble : function(event) {
		Velsn.BaseMenu.prototype._stopBubble.apply(this,arguments);
	},
	
	_ok : function(event,isHide) {
		var me = this;
		var inputs = me._div.find("input");
		var startValue = inputs[0].value;
		var endValue = inputs[1].value;
		if (startValue && endValue && parseInt(startValue) > parseInt(endValue)) {
			if (event) 
				me._showCue(event);
			return;
		}else if (startValue || endValue) 
			me._input.value = this._getConfig('prefix') +
			(startValue ? startValue : 0) + " 到 " + (endValue ? endValue : "不限") +
			this._getConfig('suffix');
		if (!isHide) 
			me.hide();
	},
	
	_getConfig: function(itemName){
		var me = this;
		return (me._config && me._config[itemName])?me._config[itemName]:"";
	},
	
	setUiId : function(startInputId,endInputId) {
		var me = this;
		var inputs = me._div.find("input");
		inputs[0].id = startInputId;
		inputs[0].name = startInputId;
		inputs[1].id = endInputId;
		inputs[1].name = endInputId;
	},
	
	getValue : function() {
		var me = this;
		var inputs = me._div.find("input");
		return [inputs[0].value,(inputs[1].value == "不限" ? "" : inputs[1].value)];
	},
	
	setValue : function(value) {
		var me = this;
		var inputs = me._div.find("input");
		if (isNaN(value[0])) 
			inputs[0].value = "";
		else
			inputs[0].value = value[0];
		if (isNaN(value[1])) 
			inputs[1].value = "";
		else
			inputs[1].value = value[1];
		me._ok();
	},
	
	reset : function() {
		this._clear();
	},
	
	_clear : function() {
		var me = this;
		var inputs = me._div.find("input");
		inputs[0].value = "";
		inputs[1].value = "";
		if (me._config.title) 
			me._input.value = me._config.title;
		else
			me._input.value = "";
	}
	
});
Velsn.BaseMenu = Velsn.Class({
	
	construct : function(datas){
		var me = this;
		me._isAutoWidth = (datas.isAutoWidth != null && datas.isAutoWidth != undefined && datas.isAutoWidth != "null" && datas.isAutoWidth != "undefined") ? datas.isAutoWidth : true;
		if (datas.width) {
			me._width = datas.width;
			me._div.width(me._width);
		}
		me._isShowScroll = datas.isShowScroll;
		me._maxHeight = datas.maxHeight ? datas.maxHeight : 300;
		me._initListener();
		me._closeCB = datas.closeCB;
	},
	
	_initListener : function() {
		var me = this;
		me._div.unbind("mouseover")
		me._div.find("div").mouseover(function(event){
			var div = Velsn.Tools.getTarget(event);
			if (me._currentDiv && div != me._currentDiv) 
				$(me._currentDiv).css("background-color","");
			$(div).css("background-color","#ffffca");
			me._currentDiv = div;
		});
	},
	
	show : function(event) {
		var me = this;
		if (!me._isShow) {
			me._input = Velsn.Tools.getTarget(event);
			var point = Velsn.Tools.absPos(me._input);
			me._div.css("left",point.x);
			me._div.css("top",point.y + me._input.offsetHeight);
			if (me._isAutoWidth) 
				me._div.width(me._input.offsetWidth-2);
			if (me._isShowScroll && me._maxHeight && me._div.height() >= me._maxHeight) {
				me._div.css("height",me._maxHeight + "px");
				me._div.css("overflow-y","auto");
			}else
				me._div.css("height","auto");
			me._div.slideDown("fast");
			me._div.click(function(event){
				me._stopBubble(event);
//				console.log("me._div");
			});
			$(me._input).click(function(event){
				me._stopBubble(event);
//				console.log("me._input");
			});
			$(document).one("click",function() {
				me.hide();
//				console.log("document");
			});
//			me._stopBubble(event);
			me._isShow = true;
			if(event)
				event.stopPropagation(); //防止document事件关闭本身
		}
	},
	
	_stopBubble : function(event) {
		if (window.event)
			window.event.cancelBubble = true;
		else if(event.stopPropagation)
			event.stopPropagation();
	},
	
	reset : function() {
	},
	
	hide : function() {
		var me = this;
		if(me._isShow){
			me._div.slideUp("fast");
			//$(document).unbind("click");
			me._isShow = false;
			if(me._closeCB)
				me._closeCB();
		}
	}
	
});
Velsn.TagMenu = Velsn.Class(Velsn.BaseMenu,{
	
	construct : function(datas,input){
		var me = this;
		me._input = input;
		me._datas = datas;
		me._tags = [];
		me._selectedIds = [];
		me._div = $('<div style="font-size:12px;background-color:#F5F5F5;width:170px;position:absolute;display:none;z-index:3000;" class="popmenu"></div>');
		me._div.appendTo($("body"));
		me._generateContext();
		Velsn.BaseMenu.prototype.construct.apply(me,arguments);
		me._isAutoWidth = false;
	},
	
	_initListener : function() {
		var me = this;
		me._div.unbind("click")
		me._div.click(function(event){
			var div = $(Velsn.Tools.getTarget(event));
			if (div.attr("cmd") == "tag") {
				me._setTabStyle(div);
				me._changeTag(div.attr("data"));
			}else if (div.attr("cmd") == "menu"){
				me._div.find("input[cmd=selectAll]").attr("checked",false);
				me._select(Velsn.Tools.getTarget(event));
			}else if (div.attr("cmd") == "selectAll"){
				me._selectAll(Velsn.Tools.getTarget(event));
			}
		});
	},
	
	_setTabStyle : function (target) {
		var me = this;
		if (me._currentTagDiv) {
			me._currentTagDiv.css("border-style","none none none none");
			me._currentTagDiv.css("background-color","#E7E7E7");
		}
		target.css("border-style","solid none solid solid");
		target.css("border-color","#A0A09E #F5F5F5 #A0A09E #A0A09E");
		target.css("background-color","#F5F5F5");
		me._currentTagDiv = target;
	},
	
	_generateContext : function () {
		var me = this;
		me._tagDiv = '<div id="tags" style="background-color:#E7E7E7;width:55px;height:100%;float:left;" class="leftTree">';
		me._div.html("");
		var maxMenuCount = 0;
		for ( var i = 0; i < me._datas.length; i++) {
			maxMenuCount = (me._datas[i].menus.length + 1) > maxMenuCount ? (me._datas[i].menus.length + 1) : maxMenuCount;
			me._tags[i] = new Velsn.TagMenu.Tag(me._datas[i]);
			me._tagDiv += '<div cmd="tag" data="'+me._datas[i].id+'" style="width:55px;cursor:pointer;border:1px solid #A0A09E;border-style:none none none none;padding:2px;" class="">'+me._datas[i].name+'</div>';
		}
		me._tagDiv += '</div>';
		me._tagDiv = $(me._tagDiv);
		me._tagDiv.appendTo(me._div);
		if (maxMenuCount * 17 >= me._datas.length * 15) 
			me._tagDiv.css("height",(maxMenuCount * 19)+"px");
		me._menuDiv = $('<div id="menuDiv" style="margin-left: 5px; float: left;"></div>');
		me._menuDiv.appendTo(me._div);
		me._changeTag(me._tags[0].id());
	},
	
	show : function(event) {
		Velsn.BaseMenu.prototype.show.apply(this,arguments);
	},
	
	_select : function(target) {
		var me = this;
		if (target.nodeName == "DIV") {
			var input = $(target).find("input");
			input.attr("checked",input.attr("checked") ? false : true);
		}
		var inputs = me._div.find("input:checked[cmd=menu]");
		var result = "";
		me._selectedIds = [];
		for ( var i = 0; i < inputs.length; i++) {
			if (i!=0) 
				result += ",";
			result += $(inputs[i]).attr("context");
			me._selectedIds[i] = $(inputs[i]).attr("value");
		}
		if (inputs.length == 0) 
			me._selectedIds = [];
		if (me._selectedIds.length == me._currentTag.menu().length) {
			me._input.value = me._currentTag.name() +": ";
			me._div.find("input[cmd=selectAll]").attr("checked",true);
		}
		else if(me._selectedIds.length == 0)
			me._input.value = "";
		else
			me._input.value = me._currentTag.name() +": "+result;
	},
	
	_selectAll : function(input){
		var me = this;
		if (input.nodeName == "DIV") {
			input = $(input).find("input");
			input.attr("checked",input.attr("checked") ? false : true);
		}
		me._div.find("input").attr("checked",$(input).attr("checked") ? true : false);
		me._select({});
	},
	
	selectAll : function(isSelectAll){
		var me = this;
		var selectAllInput = me._div.find("input[cmd=selectAll]");
		selectAllInput.attr("checked",isSelectAll);
		me._selectAll(selectAllInput.get(0));
	},
	
	_changeTag : function (tagId) {
		var me = this;
		me._setTabStyle(me._div.find("div[data="+tagId+"]"));
		for ( var i = 0; i < me._tags.length; i++) {
			if (me._tags[i].id() == tagId) {
				me._tags[i].reset();
				me._currentTag = me._tags[i];
				me._menuDiv.html(me._tags[i].getMenuDiv());
				if (me._tagDiv.height() < me._menuDiv.height()) 
					me._tagDiv.height(me._menuDiv.height());
				break;
			}
		}
		if (me._input) 
			me._input.value = "";
	},
	
	setValue : function (tag) {
		var me = this;
		for ( var i = 0; i < me._tags.length; i++) {
			if (me._tags[i].id() == tag.id) {
				me._changeTag(tag.id);
				me._tags[i].setValue(tag.menus);
				me._select({});
				break;
			}
		}
	},
	
	setDatas : function(datas) {
		var me = this;
		me._datas = datas;
		me._generateContext();
		me._selectedId = [];
		me._initListener();
	},
	
	reset : function () {
		var me = this;
		me._input.value = "";
		me._currentTag.reset();
		me._selectedIds = [];
	},
	
	isSelectAll : function(){
		return this._currentTag.isSelectAll();
	},

	
	getValue : function() {
		var me = this;
		if (me._selectedIds.length == 0 && !me._div.find("input[cmd=selectAll]").attr("checked")) 
			return null;
		else
			return me._currentTag.getValue(me._selectedIds);
	}
	
});
Velsn.TagMenu.Tag = Velsn.Class({
	
	construct : function(tag){
		var me = this;
		me._data = tag;
		me._id = tag.id;
		me._name = tag.name;
		me._menus = tag.menus;
		me._menuDiv = $('<div style="overflow-x:hidden;overflow-y:auto;"></div>');
		me._generateContext();
	},
	
	_generateContext : function () {
		var me = this;
		var menu;
		for ( var i = 0; i < me._menus.length; i++) {
			menu = $('<div cmd="menu" style="cursor:pointer;white-space: nowrap;width: 90px;height:17px; overflow-x: hidden;" class="item"><label><input cmd="menu" type="checkbox" value="'+me._menus[i].id+'" context="'+me._menus[i].name+'" />'+me._menus[i].name + '</label></div>');
			menu.appendTo(me._menuDiv);
		}
		menu = $('<div cmd="selectAll" style="cursor:pointer;white-space: nowrap;width: 80px;height:17px; overflow-x: hidden;"  class="item"><label><input cmd="selectAll" type="checkbox" />全选</label></div>');
		menu.appendTo(me._menuDiv);
	},
	
	id : function (value) {
		var me = this;
		if (value) 
			me._id = value;
		else
			return this._id;
	},
	
	name : function (value) {
		var me = this;
		if (value) 
			me._name = value;
		else
			return this._name;
	},
	
	menu : function(){
		return this._menus;
	},
	
	isSelectAll : function(){
		return this._selectedIds.length == this._menus.length;
	},
	
	reset : function() {
		var me = this;
		var inputs = me._menuDiv.find("input");
		for ( var i = 0; i < inputs.length; i++) {
			inputs[i].checked = false;
		}
		me._selectedIds = [];
	},
	
	getValue : function (ids) {
		var me = this;
		var tempMenus = [];
		var k = 0;
		for ( var i = 0; i < me._data.menus.length; i++) {
			for ( var j = 0; j < ids.length; j++) {
				if (me._data.menus[i].id == ids[j]) {
					tempMenus[k++] = me._data.menus[i];
					break;
				}
			}
		}
		var result = {};
		for ( var key in me._data) {
			result[key] = me._data[key];
		}
		result.menus = tempMenus;
		return result;
	},
	
	setValue : function(menus){
		var me = this;
		var inputs = me._menuDiv.find("input");
		for (var i = 0; i < menus.length; i++) {
			for (var j = 0; j < inputs.length; j++) {
				if ($(inputs[j]).attr("value") == menus[i].id || encodeURIComponent($(inputs[j]).attr("value")) == menus[i].id) {
					$(inputs[j]).attr("checked",true);
					break;
				}
			}
		}
	},
	
	getMenuDiv : function () {
		return this._menuDiv;
	}
	
});
Velsn.DropDownMenu = Velsn.Class(Velsn.BaseMenu,{
	
	construct : function(datas,input){
		var me = this;
		me._input = input;
		me._datas = datas;
		me._okCB = datas.okCB;
		me._div = $('<div style="width:100px;overflow-x:hidden;position:absolute;display:none;z-index:3000;background-color:#E7E7E7;" class="popmenu"></div>');
		me._div.appendTo($("body"));
		me._generateContext();
		me._isAutoWidth = true;
		Velsn.BaseMenu.prototype.construct.apply(me,arguments);
	},
	
	_generateContext : function() {
		var me = this;
		var menus = "";
		me._div.html("");
		for ( var i = 0; i < me._datas.length; i++) {
			menus += '<div class="item" style="cursor:pointer;white-space: nowrap;padding:2px 6px 2px 4px;" uiData="'+me._datas[i].uiData+'" data="'+(me._datas[i].id||me._datas[i].ID)+'">'+(me._datas[i].name||me._datas[i].NAME) + '</div>';
		}
		if (me._datas.length == 0) {
			menus += "<span>无数据</span>";
		}
		$(menus).appendTo(me._div);
		if (me._datas.length > 0) {
			me._div.find("div").click(function(event){
				me._select(Velsn.Tools.getTarget(event));
				me.hide();
			});
		}
	},
	
	setValue : function(ids){
		var me = this;
		var divs = me._div.find("div");
		for (var i = 0; i < ids.length; i++) {
			for (var j = 0; j < divs.length; j++) {
				if ($(divs[j]).attr("data") == ids[i] || encodeURIComponent($(divs[j]).attr("data")) == ids[i]) {
					me._select(divs[j]);
					break;
				}
			}
		}
	},
	
	_select : function(target) {
		var me = this;
		me._input.value = $(target).html();
		if (me._input.onchange) 
			me._input.onchange.apply();
		me._selectedId = $(target).attr("data");
		/**
		 * update 2012年2月28日18:52:10
		 */
		$(me._input).attr("keyId",$(target).attr("data"));
		
		if ($(target).attr("uiData")) 
			$(me._input).attr("uiData",$(target).attr("uiData"));
		if (me._okCB) 
			me._okCB();
	},
	
	show : function(event) {
		var me = this;
		Velsn.BaseMenu.prototype.show.apply(this,arguments);
		var divs = me._div.find("div");
		for ( var i = 0; i < divs.length; i++) {
			divs[i].style.width = me._input.offsetWidth +"px";
		}
	},
	
	setDatas : function(datas) {
		var me = this;
		me._datas = datas;
		me._generateContext();
		me._selectedId = null;
		me._initListener();
	},
	
	hide : function() {
		Velsn.BaseMenu.prototype.hide.apply(this,arguments);
	},
	
	_stopBubble : function(event) {
		Velsn.BaseMenu.prototype._stopBubble.apply(this,arguments);
	},
	
	reset : function() {
		this._selectedId = null;
	},
	
	getValue : function() {
		return this._selectedId;
	}
	
});
Velsn.CheckBoxMenu = Velsn.Class(Velsn.DropDownMenu,{
	
	construct : function(datas,input){
		this._isAutoSelectAll = datas.isAutoSelectAll;
		Velsn.DropDownMenu.prototype.construct.apply(this,arguments);
	},
	
	_generateContext : function() {
		var me = this;
		var menus = "";
		var datas=me._datas.datas||me._datas;
		me._div.html("");
		for ( var i = 0; i < datas.length; i++) {
			menus += '<div class="item" style="cursor:pointer;white-space: nowrap;"><input '+(datas[i].uiId ? 'id="'+datas[i].uiId+'" name="'+datas[i].uiId+'"' : '')+'type="checkbox" value="'+datas[i].id+'" context="'+datas[i].name+'" />'+datas[i].name + '</div>';
		}
		if (datas.length == 0) {
			menus += '<span style="color:red;">无数据</span>';
		}
		$(menus).appendTo(me._div);
		if (datas.length > 0) {
			me._div.find("div").click(function(event){
				me._select(Velsn.Tools.getTarget(event));
			});
		}
	},
	
	_select : function(target) {
		var me = this;
		if (target.nodeName == "DIV") {
			var input = $(target).find("input");
			input.attr("checked",input.attr("checked") ? false : true);
		}
		var inputs = me._div.find("input:checked");
		var result = "";
		me._selectedIds = [];
		for ( var i = 0; i < inputs.length; i++) {
			if (i!=0) 
				result += ",";
			result += $(inputs[i]).attr("context");
			me._selectedIds[i] = $(inputs[i]).attr("value");
		}
		if (inputs.length == 0) 
			me._selectedIds = [];
		me._input.value = result;
	},
	
	show : function(event) {
		Velsn.DropDownMenu.prototype.show.apply(this,arguments);
	},
	
	setDatas : function(datas) {
		Velsn.DropDownMenu.prototype.setDatas.apply(this,arguments);
	},
	
	hide : function() {
		var me = this;
		Velsn.DropDownMenu.prototype.hide.apply(me,arguments);
		if (me._isAutoSelectAll && (!me._selectedIds || me._selectedIds.length == 0)) 
			me._selectAll();
	},
	
	_selectAll : function(){
		var me = this;
		me._div.find("input").attr("checked",true);
		me._select({});
	},
	
	_stopBubble : function(event) {
		Velsn.DropDownMenu.prototype._stopBubble.apply(this,arguments);
	},
	
	reset : function() {
		var me = this;
		var inputs = me._div.find("input");
		for ( var i = 0; i < inputs.length; i++) {
			inputs[i].checked = false;
		}
		me._input.value = "";
		me._selectedIds = [];
	},
	
	setValue : function(ids){
		var me = this;
		var inputs = me._div.find("input");
		for (var i = 0; i < ids.length; i++) {
			for (var j = 0; j < inputs.length; j++) {
				if ($(inputs[j]).attr("value") == ids[i] || encodeURIComponent($(inputs[j]).attr("value")) == ids[i]) {
					$(inputs[j]).attr("checked",true);
					me._select(inputs[j]);
					break;
				}
			}
		}
	},
	
	getValue : function() {
		return this._selectedIds;
	}
	
});
var dd = Velsn.MenuManager;
var inputPrompts = {}

function showScopeInputMenu(event,datas){
	Velsn.MenuManager.show(event,datas,"ScopeInputMenu");
}

function resetMenuValue(id) {
	var menu = Velsn.MenuManager.getMenu(id)
	if (menu)
		menu.reset();
}
function resetInputElement(elId) {
	resetMenuValue(elId);
	resetRawInputElement(elId);
}
function resetRawInputElement(elId) {
	$('#' + elId).val(inputPrompts[elId]);
}